import time

from selenium.webdriver.common.by import By

from BasePage.basepage import BasePage


class PageSearch(BasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver
        # 点击首页 com.tpshop.malls:id/home_img
        self.mine_loc = (By.ID, "com.tpshop.malls:id/home_img")
        # 点击搜索 com.tpshop.malls:id/default_search_et
        self.search_loc = (By.ID, "com.tpshop.malls:id/default_search_et")
        # 输入搜索值 com.tpshop.malls:id/search_et
        self.search_input = (By.ID, "com.tpshop.malls:id/search_et")
        # 点击搜索按钮 com.tpshop.malls:id/search_btn
        self.search_clic = (By.ID, "com.tpshop.malls:id/search_btn")
        # 断言：com.tpshop.malls:id/product_name_tv
        self.search_goods = (By.ID, "com.tpshop.malls:id/product_name_tv")


    def search_input_goods(self, search_input):
        time.sleep(6)
        self.click_element(self.mine_loc)
        time.sleep(2)
        self.click_element(self.search_loc)
        time.sleep(2)
        self.base_clear_input(self.search_input, search_input)
        self.click_element(self.search_clic)

    def search_assert(self):
        time.sleep(2)
        aa=self.get_element(self.search_goods).text
        return aa
